public class Assigner {

	private Expressions e;
	private String name;

	public Assigner(Tokens tokens){
		this.parse(tokens);
	}
	
	public void parse(Tokens tokens) {
		this.name = tokens.idName();
		tokens.skipToken();
		// check for '=' sign
		if(tokens.getToken() != 14){
			System.err.println("There must be an '=' sign after " + this.name + " for assignments");
			System.exit(0);
		}
		tokens.skipToken();
		this.e = new Expressions(tokens);	
		// check for semicolon
		if(tokens.getToken() != 12){
			System.err.println("Assignment for " + this.name + "must end with a semicolon");
			System.exit(0);
		}
		tokens.skipToken();
	}
	
	public void runAssign(){
		if(this.e != null){
			int tmp = this.e.runExp();
			Id.updateID(this.name, tmp);
		}
	}

}